package com.lwww.infinitechat.authenticationservice.common;

import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.http.HttpStatus;

@Data
@Accessors(chain = true)
public class Result<T> {
    private int code;

    private String msg;

    private T data;

    public static <T>Result success(T data){
        Result result = new Result<>();
        result.setCode(HttpStatus.OK.value());
        result.setData(data);
        return result;
    }

    public static Result databaseError(String msg){
        return new Result().setCode(HttpStatus.INTERNAL_SERVER_ERROR.value()).setMsg(msg); //链式编程
    }


    public static Result<?> serverError(String msg) {
        return new Result<>().setCode(HttpStatus.INTERNAL_SERVER_ERROR.value()).setMsg(msg);
    }

    public static Result<?> userError(int code, String message) {
        return new Result<>().setCode(code).setMsg(message);
    }
}
